#!/bin/bash

NUM_OF_THREAD=3
RESULT_DIR=./wtp_result
SLEEP_FOR=60

rm -rf $RESULT_DIR
mkdir -p $RESULT_DIR

echo "invoke processes"
for((i=0;i<$NUM_OF_THREAD;i++))
do
	./TestParser > $RESULT_DIR/result$i 2>&1 &
done

echo "sleep for $SLEEP_FOR" 
sleep $SLEEP_FOR

echo "kill all processes"
while :
do
    pkill -f TestParser
    currNum=`pgrep -fl TestParser | wc -l`
    if [ $currNum -eq 0 ]
    then
        break
    fi
done

echo "count result"
SUM=`cat $RESULT_DIR/* | grep "_TITLE" | wc -l`
AVG=$(($SUM / $SLEEP_FOR))
echo "RESULT: $AVG"
